import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import elementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import api from './util/api'
import './util/mySessionStorage.js'
import './util/myLocalStorage.js'

import mouseclick from './util/mouseclick'
import 'highlight.js/styles/default.css';

import Hljs from 'highlight.js'

const setting = myLocalStorage.getItem("setting", { lzxg: true })
mouseclick.setLzxg(setting.lzxg)

Vue.directive('highlight', function (el) {
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach((block) => {
    Hljs.highlightElement(block)
  })
})

const isDev = process.env.NODE_ENV === 'development'
const onlyFront = true
let baseUrl = mySessionStorage.getItem("baseUrl", isDev ? (onlyFront ? 'http://192.168.1.60:9000' : "http://" + location.hostname + ":8088") : location.origin)

Vue.use(api, { baseUrl: baseUrl })

Vue.use(elementUI, { size: "mini" })
Vue.config.productionTip = false

document.addEventListener('keydown', e => {
  if (e.code === 'KeyS' && e.ctrlKey) {
    // 禁止保存
    e.preventDefault()
  }
  // if ((e.code === 'NumpadSubtract' || e.code === 'NumpadAdd' || e.code === 'Minus' || e.code === 'Equal') && e.ctrlKey) {
  //   // 禁止缩放
  //   e.preventDefault()
  // }
})
// document.addEventListener("wheel", e => {
//   if (e.ctrlKey) {
//     // 禁止缩放
//     e.preventDefault()
//   }
// }, { passive: false })
Vue.prototype.$api.getXtInfo().then(xtInfo => {
  store.commit("setXtInfo", xtInfo)
  let yhxx = mySessionStorage.getItem("yhxx");
  if (yhxx) {
    document.title = yhxx.mc + "-"
  }
  document.title += `规则引擎-规则设计器-${xtInfo.gzyqVersion}`
})
Vue.prototype.$listToTree = (data, id, pid) => {
  let itemObj = {}
  for (let item of data) {
    item.children = []
    itemObj[item[id]] = item
  }
  let arr = []
  for (let item of data) {
    if (itemObj[item[pid]]) {
      itemObj[item[pid]].children.push(item)
    } else {
      arr.push(item)
    }
  }
  return arr
}


// (async () => {
//   let url = "http://192.168.3.194/bd-service/api/model/getModelCategoryList?xtbz=TYAK&dwbm=100000"
//   let res = await axios.get(url)
//   let arr = []
//   for (const item of res) {
//     let newUrl = `http://192.168.3.194/bd-service/api/model/getModelList?xtbz=TYAK&mxflbm=${item.mxflbm}`
//     let newRes = await axios.get(newUrl)
//     for (const newRe of newRes) {
//       arr.push({
//         mxmc: newRe.mxmc,
//         mxbm: newRe.mxbm,
//       })
//     }
//   }
//   console.log(JSON.stringify(arr))
// })();

window.addEventListener("contextmenu", e => e.preventDefault())
Vue.mixin({
  methods: {
    $contextmenu (contextmenu) {
      let e = new CustomEvent("contextmenuEvent", {
        detail: {
          ev: event, contextmenu
        }
      })
      window.dispatchEvent(e)
    }, $hideContextmenu () {
      let e = new CustomEvent("contextmenuHideEvent")
      window.dispatchEvent(e)
    }
  }
})

new Vue({
  router, store, render: h => h(App)
}).$mount('#app')
